'''
knn, k nearest neighbor
k最近邻
'''
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score

X,y = load_iris(return_X_y=True)
X_train,X_test,y_train,y_test = train_test_split(X,y,train_size=0.2)

kNN = KNeighborsClassifier(n_neighbors=3)
kNN.fit(X_train,y_train)
a = accuracy_score(y_test,kNN.predict(X_test))
print(a)